<?php include('header.php');

$qy = $db->findall('category');
while($row = $db->fetch_array($qy))
{
	$category_arr[$row[id_category]] = $row[Category_name];
}



if (isset($_POST[Submit])) {


    $name = $_POST['Category_name'];
	$id_parent = $_POST['id_parent'];


    $db->insert('category', "Category_name,id_parent", "$name','$id_parent");
   $db->Get_admin_msg("category_add.php","add success");
}


?>
<script>

$(function(){

$('#form').validate({
	rules:{
		
		Category_name:'required'
	},
	messages:{
		Category_name:'category name empty'
	}
	});

});

</script><style type="text/css">
<!--
body {
	background-color: #E1E1E1;
}
body,td,th {
	font-family: Trebuchet MS;
}
-->
</style>

<div id="wapper" style="width:980px;margin:0 auto">
    <form action="" method="post" id="form" enctype="multipart/form-data">
        <div class="MainDiv">
            <table width="99%" border="0" cellpadding="0" cellspacing="0" class="CContent">
                <tr>
                    <th class="tablestyle_title" >add category   (<a href="category_list.php">category list</a>)</th>
                </tr>
                
                    <TD width="100%"><fieldset style="height:100%;">
                            <legend>basic infomation</legend>
                            <table border="0" cellpadding="2" cellspacing="1" style="width:100%">
                                <tr>
                                    <td width="15%" align="right">name:</td>
                                    <td width="65%"><input type="text" name="Category_name" id="Category_name" value="" style="width: 45%;"/></td>
                                    <td width="10%" align="right">&nbsp;</td>
                                    <td width="10%">&nbsp;</td>
                                </tr>
                                <tr>
                                    <td width="15%" align="right">parent category:</td>
                                    <td width="65%">
                                     
                                    <select name="id_parent">
                                    	<option value="0">no</option>
                                    <?php 
									
									if(is_array($category_arr)) {
										foreach($category_arr as $key=>$value){
											?>
											
											<option value="<?php echo $key;?>"><?php echo $value;?></option>
											
											<?php	
										}
									}
									?>
                                    

                                    </select>
                                    </td>
                                    <td width="10%" align="right">&nbsp;</td>
                                    <td width="10%">&nbsp;</td>
                                </tr>
                                <TR>
                                    <TD colspan="2" align="center" height="50px"><input type="submit" name="Submit" value="add" class="button" /></TD>
                                </TR>
                            </table>
                            <br />
                        </fieldset></TD>
                </TR>
            </TABLE>
            </td>
            </tr>
            </TABLE>
            </td>
            </tr>
            </table>
        </div>
    </form>
    <?php include('footer.php')?>